
import 'package:baselib/utils/image_util.dart';
import 'package:flutter/material.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/px_util.dart';

class VoiceGradeWidget extends StatelessWidget {

  /// The volume of the user. The value ranges between 0 (lowest volume) and 255 (highest volume).
  int volume;
  bool isCloseWheat;
  VoiceGradeWidget({Key key,this.isCloseWheat,this.volume}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: ImagesUtil.loadAssetImage(
          getGradeVoiceImg(),
          width: PxUtil.instance.px_18
      ),
    );
  }

  String getGradeVoiceImg() {
    volume = volume??0;
    double volumePercent = volume*1.0/255;
    print('getGradeVoiceImg-->volume=$volume');
    print('getGradeVoiceImg-->volumePercent=$volumePercent');
    if(isCloseWheat??false)return DrawableUtil.instance.icon_portrait_voice_close;
    if(volumePercent==0)return DrawableUtil.instance.icon_portrait_voice_open;
    if((volumePercent>0)&&(volumePercent<=25))return DrawableUtil.instance.icon_portrait_voice_25;
    if((volumePercent>25)&&(volumePercent<=50))return DrawableUtil.instance.icon_portrait_voice_50;
    if((volumePercent>50)&&(volumePercent<=75))return DrawableUtil.instance.icon_portrait_voice_75;
    return DrawableUtil.instance.icon_portrait_voice_100;
    // if(vad==1){
    //
    // }else{
    //   //不是本地本人发音
    //   return DrawableUtil.instance.icon_portrait_voice_open;
    // }
  }
}
